/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package videowarehouseapp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import videowarehouseapp.Delivery.DeliveryInfo;
import videowarehouseapp.dataobjects.DeliveryDO;



/**
 *
 * @author pmae9287
 */
public class Main {

    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) throws Exception{

            System.out.println("Trying to fetch the messages");
            Delivery d=new DeliveryDO();

            String s="";
            while (!s.equals("4")) {
                try {
                        System.out.println("*********************************************");
                        System.out.println("************** Warehouse Menu ***************");
                        System.out.println("*********************************************");
                        System.out.println("");
                        System.out.println("Please, choose one of the following options :");
                        System.out.println("");
                        System.out.println("1- Ship Delivery"); //Ask for delivery_id
                        System.out.println("2- Delivery Status"); //Ask for delivery_id
                        System.out.println("3- List all Pending Deliveries");
                        System.out.println("4- Quit the System");
                        System.out.println("");
                        System.out.println("Write your option and press Enter key : ");
                        System.out.println("");

                        BufferedReader answer = new BufferedReader(new InputStreamReader(System.in));
                        s = answer.readLine();

                        if (s.equals("1")) {
                            System.out.println("");
                            System.out.println("Ship Delivery");
                            System.out.println("Please enter the Delivery ID: ");
                            BufferedReader idRead = new BufferedReader(new InputStreamReader(System.in));
                            String id=idRead.readLine();
                            Integer idInt=new Integer(id);
                            d.submitDelivery(idInt);
                        } else if (s.equals("2")) {
                            System.out.println("");
                            System.out.println("Check Delivery Status");
                            System.out.println("Please enter the Delivery ID: ");
                            BufferedReader idRead = new BufferedReader(new InputStreamReader(System.in));
                            String id=idRead.readLine();
                            try{
                                Integer idInt=new Integer(id);
                                DeliveryInfo di=d.getDeliveryById(idInt);
                                System.out.println("Delivery "+di.id+" tiene status "+di.status);
                            }catch (NumberFormatException e){System.out.println("Please introduce a number");}
                        } else if (s.equals("3")) {
                            System.out.println("");
                            System.out.println("List all Pending Orders");
                            System.out.println("");
                        } else if (s.equals("4")) {
                            System.out.println("");
                            System.out.println("Quit the System");
                            System.out.println("");
                            DeliveryMgr.getInstance().stopQueueListener();
                            System.exit(0);
                        } else{
                            System.out.println("");
                            System.out.println("Invalid option. Please, select one of listed options.");
                            System.out.println("");
                        }

                } catch (IOException e) {
                    System.err.println("I/O exception: " + e.toString());
                }
            }

    }

}
